package voldTransfo;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.eclipse.emf.common.util.EList;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import uml2Java.JavaChargeur;
import astjava.Model;
import astjava.Package;

public class TestJavaPersistance {
	
	private String _sourcePath;
	private String _ciblePath;
	private JavaChargeur _chargeur;
	private OldUML2Java _uml2java;

	@Before
	public void setUp() throws Exception {
		_ciblePath = "modele_de_test/testTransfo.astjava";
		_sourcePath = "modele_de_test/test.uml";
		_uml2java = new OldUML2Java(_sourcePath);
		_chargeur = new JavaChargeur(_ciblePath);
	}
	
	@Test
	public void testCreateModel() {
		assertNotNull(_uml2java.get_modeleCible());
	}
	
	@Test
	public void testTransfoPackage() {
		_uml2java.packageUML2PackageJava();
		EList<Package> packageRacine=  _uml2java.get_modeleCible().getOwnedElements();
		assertFalse(packageRacine.size() == 0);
		assertEquals(packageRacine.get(0).getName(), "package_racine");
		assertTrue(packageRacine.get(0).getOwnedPackages().size()==2);
		assertEquals(packageRacine.get(0).getOwnedPackages().get(0).getName(), "test1");
		assertEquals(packageRacine.get(0).getOwnedPackages().get(1).getName(), "test2");
	}
	
	@Test
	public void testSaveModel() {
		_uml2java.packageUML2PackageJava();
		_chargeur.save(_uml2java.get_modeleCible());
		Model javaTestSaveModel = _chargeur.loadJavaModel();
		assertNotNull(javaTestSaveModel);
		EList<Package> packageRacine=  javaTestSaveModel.getOwnedElements();
		assertFalse(packageRacine.size() == 0);
		assertEquals(packageRacine.get(0).getName(), "package_racine");
		assertTrue(packageRacine.get(0).getOwnedPackages().size()==2);
		assertEquals(packageRacine.get(0).getOwnedPackages().get(0).getName(), "test1");
		assertEquals(packageRacine.get(0).getOwnedPackages().get(1).getName(), "test2");
	}
	
	@After
	public void tearDown() throws Exception {
		_uml2java = null;
		_chargeur = null;
	}

}
